package SolveQuestions;

import java.util.Scanner;

public class aLiInterview {

    public int getOpNum(int[] nums) {
        int minOp = Integer.MAX_VALUE;

        for(int i = 0; i < nums.length; i ++) {
            int target = nums[i];
            int op = 0;
            for(int j = 0; j < nums.length; j ++) {
                op += getOneCount(nums[j], target);
            }
            if(op < minOp) minOp = op;
        }
        return minOp;
    }

    public int getOneCount(int x, int target) {
        x = x ^ target;
        int result = 0;

        while(x != 0) {
            if((x & 1) == 1) result += 1;
            x = x >>> 1;
        }
        return result;
    }

    public static void main(String[] args) {
        Scanner input = new Scanner(System.in);
        int n = input.nextInt();
        int[] nums = new int[n];
        int count = 0;
        while(input.hasNext()) {
            nums[count++] = input.nextInt();
        }
        aLiInterview a = new aLiInterview();
        int res = a.getOpNum(nums);
        System.out.printf("%d\n", res);
    }
}
